<template>
  <div class></div>
</template>
<script>
import axios from "@/utils/requestdp";

export default {
  name: "APIgetHourWeather",
  components: {},
  data() {
    return {};
  },
  computed: {},
  watch: {},
  mounted() {
    this.watchEvent();
  },
  methods: {
    watchEvent() {
      //先清除定时任务
      if (
        this.$store.state.daping.intervalArr["APIgetHourWeather"] != undefined
      ) {
        clearInterval(
          this.$store.state.daping.intervalArr["APIgetHourWeather"][0].interval
        );
      }

      this.loadData();
      let interval = setInterval(() => {
        this.loadData();
      }, this.$root.setting.data.dayinterval);

      this.$store.state.daping.intervalArr["APIgetHourWeather"] = [
        { interval: interval },
      ];
    },

    loadData() {
      axios.get("/wInfoController/getHourWeather").then((res) => {

        if (res.code == 200) {
          let totalnum = 0;
          res.data.map((item) => {
            totalnum += Number(item.temperature);
          });

          this.$store.state.daping.pingjunwendu = totalnum / 24;
          this.$store.state.daping.tianqi = res.data[0]
        }
      });
    },
  },
};
</script>
<style lang='scss' scoped>
</style>